<<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        function sum(){
            var n=document.getElementById("num").value;
        var i=1,sum=1;
        while(i<=n){
            sum=sum* i;
            i++;
        }
        console.log(sum);
    }
    </script>
</head>
<body>
    <h2>计算阶乘</h2>
    <input type="text" id="num">
    <button onclick="sum()">计算阶乘</button>
</body>
</html>